package com.carserver.controller;

import com.carserver.common.Result;
import com.carserver.pojo.Buy_detail;
import com.carserver.service.Buy_detailDao;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/buy_detail")
public class Buy_detailController {
    @Resource
    Buy_detailDao dao;


    @PostMapping("/save")
    public Result save_buy_detail(@RequestBody Buy_detail detail){
        dao.save(detail);
        return Result.success(detail);
    }

    @DeleteMapping("/{user_id}/{str}")
    public Result delete_buy_detail(@PathVariable("user_id") Integer id,@PathVariable("str") String str){
        System.out.println(1);
        dao.deleteBuy_detailByUser_idAndCarPartsName(id,str);
        return Result.success(id);
    }
    @GetMapping("/{user_id}")
    public Result get_by_userId(@PathVariable Integer user_id){
        List<Buy_detail> list=dao.findBuy_detailByUser_id(user_id);
        return Result.success(list);
    }

    @DeleteMapping("/deleteAll/{user_id}")
    public  Result deleteAllByUserId(@PathVariable("user_id") Integer user_id){
        dao.deleteAllByUser_id(user_id);
        return Result.success(user_id+"号顾客的订单全部删除");
    }

    @GetMapping("/findone/{user_id}/{str}")
    public Result find_by_car_number(@PathVariable("user_id") Integer id,@PathVariable("str") String str){
        Buy_detail s=dao.findBuy_detailByUser_idAndCarNumber(id,str);
        return Result.success(s);
    }
}

